package com.xs.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xs.service.MajorService;
import com.xs.serviceimpl.MajorServiceImpl;

@WebServlet("/MajorServlet")
public class MajorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	MajorService ms;

	public MajorServlet() { // 无参构造

		ms = new MajorServiceImpl();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 设置请求跟相应的编码
		request.setCharacterEncoding("Utf-8");
		response.setCharacterEncoding("Utf-8");

		// 从login页面hidden隐藏域得到name="method"参数,通过if判断将要实现什么功能
		String method = request.getParameter("method");

		// 信息
		if ("info".equals(method)) {
			this.info(request, response);
		}

	}

	// 获取所有专业的封装方法
	private void info(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List list = ms.getMajorInfo();
		request.setAttribute("majorInfo", list);
		request.getRequestDispatcher("upload.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
